package com.dm.pcxt.controller;

import com.dm.pcxt.common.Md5Util;
import com.dm.pcxt.common.OkHttpUtils;
import com.dm.pcxt.common.PropertyUtil;
import com.dm.pcxt.common.SessionAndGetRemote;
import com.dm.pcxt.pojo.ServiceExcel;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.poi.hssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping(value = "goPCDD")
public class GoController {
    private static final Logger logger = LoggerFactory.getLogger(GoController.class);
    private static String BACKURL = PropertyUtil.getValue("backurl");
//    private static String BACKURL = "http://222.222.33.34:6443/shglxtback";

    @Autowired
    private OkHttpUtils okHttpUtils;


    /*####################################################################################*/
    /*##############################   登陆管理    #######################################*/
    /*####################################################################################*/

    @RequestMapping(value="/login",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> goLogin(@RequestBody Map<String,Object> param, HttpServletRequest request){
        JSONObject jsonObject = JSONObject.fromObject(param);
        Map<String,String> headersParams = new HashMap<String,String>();
        headersParams.put("Content-Type","application/json;UTF-8");
        Map<String,Object> statusMap = okHttpUtils.sendPostJson(BACKURL+"/login",headersParams,jsonObject.toString(),new Object());
        JSONObject resultJson = JSONObject.fromObject(statusMap.get("data"));
        Map json = (Map) JSONObject.fromObject(resultJson);
        HttpSession session = request.getSession();
        if("2".equals(json.get("status").toString())){
            return json;
        }
        if("0".equals(json.get("status").toString())){
            return json;
        }
        if(!"安保部".equals(json.get("bm").toString())&&!"集团办公室".equals(json.get("store").toString())){
            json.put("status","0");
            return json;
        }
        if(json.size()>1){
            String username = json.get("username").toString();
            String store = json.get("store").toString();
            String userno = json.get("userno").toString();
            String bm = json.get("bm").toString();
            session.setAttribute("userno",userno);
            session.setAttribute("username",username);
            session.setAttribute("store",store);
            session.setAttribute("bm",bm);
            session.setMaxInactiveInterval(60*60*4);
        }
        return json;
    }

    /**
         * @Description 初始化界面 查看是否存有session 并获取所有门店
         * @Author zhangxue
         * @Date 16:29 2018/7/11
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/initPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initPage(HttpSession session){
        String username = session.getAttribute("username")!=null?session.getAttribute("username").toString():null;
        String Store = session.getAttribute("store")!=null?session.getAttribute("store").toString():null;
        String userno = session.getAttribute("userno")!=null?session.getAttribute("userno").toString():null;
        String bm = session.getAttribute("bm")!=null?session.getAttribute("bm").toString():null;
        Map<String,Object> tMap = new HashMap<>();
        tMap.put("username",username);
        tMap.put("store",Store);
        tMap.put("userno",userno);
        tMap.put("bm",bm);
        JSONObject js = new JSONObject();
        if(username==null||Store==null){
            tMap.put("status","0");
            js = JSONObject.fromObject(tMap);
            return js.toString();
        }else{
            JSONObject jsonObject = JSONObject.fromObject(tMap);
            Map<String,String> headersParams = new HashMap<String,String>();
            headersParams.put("Content-Type","application/json;UTF-8");
            Map<String,Object> statusMap = okHttpUtils.sendPostJson(BACKURL+"/initPage",headersParams,jsonObject.toString(),new Object());
            statusMap.put("status","1");
            statusMap.put("store",Store);
            statusMap.put("username",username);
            statusMap.put("userno",userno);
            statusMap.put("bm",bm);
            js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
    }

    /**
     * @Description 初始化派车界面 查看是否存有session 并获取限行信息
     * @Author zhangxue
     * @Date 16:29 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/initPaiPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initPaiPage(HttpSession session){
        String username = session.getAttribute("username")!=null?session.getAttribute("username").toString():null;
        String Store = session.getAttribute("store")!=null?session.getAttribute("store").toString():null;
        String userno = session.getAttribute("userno")!=null?session.getAttribute("userno").toString():null;
        String bm = session.getAttribute("bm")!=null?session.getAttribute("bm").toString():null;
        Map<String,Object> tMap = new HashMap<>();
        tMap.put("username",username);
        tMap.put("store",Store);
        tMap.put("userno",userno);
        tMap.put("bm",bm);
        JSONObject js = new JSONObject();
        if(username==null||Store==null){
            tMap.put("status","0");
            js = JSONObject.fromObject(tMap);
            return js.toString();
        }else{
            JSONObject jsonObject = JSONObject.fromObject(tMap);
            Map<String,String> headersParams = new HashMap<String,String>();
            headersParams.put("Content-Type","application/json;UTF-8");
            Map<String,Object> statusMap = okHttpUtils.sendPostJson(BACKURL+"/initPaiPage",headersParams,jsonObject.toString(),new Object());
            statusMap.put("status","1");
            statusMap.put("store",Store);
            statusMap.put("username",username);
            statusMap.put("userno",userno);
            statusMap.put("bm",bm);
            js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
    }

    /**
     * @Description 初始化调度界面 获取派车司机信息和车辆信息
     * @Author zhangxue
     * @Date 16:29 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/initDisPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initDisPage(HttpSession session){
        String username = session.getAttribute("username")!=null?session.getAttribute("username").toString():null;
        String Store = session.getAttribute("store")!=null?session.getAttribute("store").toString():null;
        String userno = session.getAttribute("userno")!=null?session.getAttribute("userno").toString():null;
        String bm = session.getAttribute("bm")!=null?session.getAttribute("bm").toString():null;
        Map<String,Object> tMap = new HashMap<>();
        tMap.put("username",username);
        tMap.put("store",Store);
        tMap.put("userno",userno);
        tMap.put("bm",bm);
        JSONObject js = new JSONObject();
        if(username==null||Store==null){
            tMap.put("status","0");
            js = JSONObject.fromObject(tMap);
            return js.toString();
        }else{
            JSONObject jsonObject = JSONObject.fromObject(tMap);
            Map<String,String> headersParams = new HashMap<String,String>();
            headersParams.put("Content-Type","application/json;UTF-8");
            Map<String,Object> statusMap = okHttpUtils.sendPostJson(BACKURL+"/initDisPage",headersParams,jsonObject.toString(),new Object());
            statusMap.put("status","1");
            statusMap.put("store",Store);
            statusMap.put("username",username);
            statusMap.put("userno",userno);
            statusMap.put("bm",bm);
            js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
    }

    /**
         * @Description 派车查找司机部门下拉列表
         * @Author zhangxue
         * @Date 10:14 2018/7/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryBmByStore",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryBmByStore(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryBmByStore";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        statusMap.put("status","1");
        JSONObject js = new JSONObject();
        js = JSONObject.fromObject(statusMap);
        return js.toString();
    }

    /**
         * @Description 派车查询司机下拉
         * @Author zhangxue
         * @Date 10:42 2018/7/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryUserByStoreAndBm",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryUserByStoreAndBm(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryUserByStoreAndBm";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        statusMap.put("status","1");
        JSONObject js = new JSONObject();
        js = JSONObject.fromObject(statusMap);
        return js.toString();
    }

    /*####################################################################################*/
    /*##############################   车辆基本信息管理    ###############################*/
    /*####################################################################################*/
    /**
     * @Description 查询所有车辆信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllCars",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllSHInfos(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllCars";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 查询所有车辆下拉
         * @Author zhangxue
         * @Date 16:18 2018/9/17
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllCarNo",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> queryAllCarNo(){
        String url = BACKURL+"/queryAllCarNo";
        Map<String,Object> resultMap = SessionAndGetRemote.getRemoteResult(null,url,okHttpUtils);
        return resultMap;
    }

    /**
         * @Description 新增车辆信息
         * @Author zhangxue
         * @Date 11:12 2018/7/12
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/saveCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveSHInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/saveCar";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 删除车辆信息
         * @Author zhangxue
         * @Date 9:46 2018/7/28
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delCar(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delCar";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 修改车辆信息
         * @Author zhangxue
         * @Date 9:07 2018/7/28
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/editCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String editCar(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/editCar";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 查看车辆详情
         * @Author zhangxue
         * @Date 16:14 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/initCarInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> initCarInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/initCarInfo";
        Map<String,Object> resultMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        return resultMap;
    }

    /*####################################################################################*/
    /*##############################   驾驶人员管理    ###################################*/
    /*####################################################################################*/
    /**
     * @Description 查询所有驾驶人员信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllMen",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllMen(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllMen";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 查询所有驾驶人员下拉
     * @Author zhangxue
     * @Date 16:18 2018/9/17
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllSjName",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> queryAllSjName(){
        String url = BACKURL+"/queryAllSjName";
        Map<String,Object> resultMap = SessionAndGetRemote.getRemoteResult(null,url,okHttpUtils);
        return resultMap;
    }

    /**
     * @Description 查询所有空闲驾驶人员信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllFreeMen",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllFreeMen(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllFreeMen";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 新增驾驶人员信息
     * @Author zhangxue
     * @Date 11:12 2018/7/12
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveMan",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveMan(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/saveMan";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 查看驾驶人员详情
     * @Author zhangxue
     * @Date 16:14 2018/7/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/initManInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> initManInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/initManInfo";
        Map<String,Object> resultMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        return resultMap;
    }

    /**
     * @Description 修改驾驶人员信息
     * @Author zhangxue
     * @Date 9:07 2018/7/28
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editMan",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String editMan(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/editMan";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 删除驾驶人员信息
         * @Author zhangxue
         * @Date 9:45 2018/7/28
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delMan",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delMan(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delMan";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /*####################################################################################*/
    /*##############################   车辆调度管理--约车    #############################*/
    /*####################################################################################*/
    /**
     * @Description 查询所有约车车辆调度信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllDis(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllDis";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 查询所有车辆调度信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllDoc",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllDoc(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllDoc";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 撤销约车
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/CheYue",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String CheYue(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/CheYue";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        String uid = param.get("YueManNo")!=null?param.get("YueManNo").toString():null;
        String YueCheReason = param.get("YueCheReason")!=null?param.get("YueCheReason").toString():null;
        String txt = "您的约车申请已撤销，撤销原因："+YueCheReason;
        sendMessage(uid,"约车撤销提醒",txt,null);
        return data;
    }

    /**
     * @Description 查询所有约车车辆调度信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllYueDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllYueDis(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllYueDis";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 删除车辆调度信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delDis",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delAllDis(HttpServletRequest request){
        String ID = request.getParameter("ID");
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("ID",ID);
        String url = BACKURL+"/delDis";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    @RequestMapping(value="/yuechephone",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String yuechephone(@RequestBody Map<String,Object> param,HttpServletRequest request){
        String url = BACKURL+"/yueche";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        //给约车人发送派车成功信息
        String uid = "";
        uid = param.get("YueManNo")!=null?param.get("YueManNo").toString():null;
        if(uid==null){
            Map<String,Object> tempMap = new HashMap<String, Object>();
            tempMap.put("info","员工编号未传入");
        }
        return data;
    }

    /**
         * @Description 撤销派车为已约车状态
         * @Author zhangxue
         * @Date 15:59 2018/7/30
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delPaiInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delPaiInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delPaiInfo";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        JSONObject js = JSONObject.fromObject(data);
        List<Map<String,Object>> messageList = (List<Map<String, Object>>) js.get("paramList");

        String uid = "";
        for (int i=0;i<messageList.size();i++){
            String YueManNo = messageList.get(i).get("YueManNo")!=null?messageList.get(i).get("YueManNo").toString():null;
            if(i==0){
                uid = YueManNo;
            }else{
                uid += "|" + YueManNo;
            }
        }
        Md5Util md5Util = new Md5Util();
        String mak = "";
        try {
            mak = md5Util.get32Md5Up(uid);
        }catch (Exception e){
            e.printStackTrace();
        }
        String messageUrl = "https://wx.dmjjoa.com/hui.php";
        Map<String,String> messageParams = new HashMap<String, String>();
        messageParams.put("uid",uid);
        messageParams.put("mak",mak);
        messageParams.put("lei","bh");
        messageParams.put("tit","撤销派车成功");

        String PaiCheReason = param.get("PaiCheReason")!=null?param.get("PaiCheReason").toString():null;
        messageParams.put("txt","您提交的约车单已经撤销成功，撤销原因为 "+PaiCheReason);
        messageParams.put("ur",null);

        okHttpUtils.sendGet(messageUrl,null,messageParams,new Object());

        return data;
    }

    /**
     * @Description 派车
     * @Author zhangxue
     * @Date 15:59 2018/7/30
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/SavePaiInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String SavePaiInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/SavePaiInfo";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;

        //给约车人发送派车成功信息
        List<Map<String,Object>> YueList = param.get("selectYueS")!=null? (List<Map<String, Object>>) param.get("selectYueS") :null;
        String uid = "";
        String yuemen = "";
        String YueStartDate = "";
        String ArrivePlace = "";
        String YueManPhoneNo = "";
        String SjNo = param.get("PaiMan")!=null?param.get("PaiMan").toString():null;
        String SjPhoneNo = param.get("SjPhoneNo")!=null?param.get("SjPhoneNo").toString():null;
        for (int i=0;i<YueList.size();i++){
            String YueManNo = YueList.get(i).get("YueManNo")!=null?YueList.get(i).get("YueManNo").toString():null;

            //通过员工编号查询手机号
            Map<String,Object> tempMap = new HashMap<String, Object>();
            tempMap.put("UserNo",YueManNo);
            String queryphoneurl = BACKURL+"/queryPhoneByUserNo";
            Map<String,Object> phoneMap = SessionAndGetRemote.getRemoteResult(tempMap,queryphoneurl,okHttpUtils);
            String PhoneNo = phoneMap.get("data")!=null?phoneMap.get("data").toString():null;
            Map<String,Object> PhoneMap = JSONObject.fromObject(PhoneNo);
            PhoneNo = PhoneMap.get("PhoneNo")!=null&&!"".equals(PhoneMap.get("PhoneNo").toString())?PhoneMap.get("PhoneNo").toString():"";
            String YueMan = YueList.get(i).get("YueMan")!=null?YueList.get(i).get("YueMan").toString():null;
            YueStartDate = YueList.get(i).get("YueStartDate")!=null?YueList.get(i).get("YueStartDate").toString():null;
            String Arrive = YueList.get(i).get("ArrivePlace")!=null?YueList.get(i).get("ArrivePlace").toString():null;
            if(i==0){
                YueManPhoneNo = PhoneNo;
                uid = YueManNo;
                yuemen = YueMan;
                ArrivePlace = Arrive;
            }else{
                YueManPhoneNo += "|"+PhoneNo;
                uid += "|" + YueManNo;
                yuemen += "|"+YueMan;
                ArrivePlace += "|"+Arrive;
            }
        }

        Md5Util md5Util = new Md5Util();
        String mak = "";
        try {
            mak = md5Util.get32Md5Up(uid);
        }catch (Exception e){
            e.printStackTrace();
        }
        String messageUrl = "https://wx.dmjjoa.com/hui.php";
        Map<String,String> messageParams = new HashMap<String, String>();
        messageParams.put("uid",uid);
        messageParams.put("mak",mak);
        messageParams.put("lei","bh");
        messageParams.put("tit","派车成功");

        String SjName = param.get("SjName")!=null?param.get("SjName").toString():null;
        String PaiCarNo = param.get("PaiCarNo")!=null?param.get("PaiCarNo").toString():null;
        messageParams.put("txt","您提交的约车单已派车，所派车辆为 "+PaiCarNo+" ,所派驾驶人姓名为 "+SjName+" ，司机手机号为 "+SjPhoneNo);
        messageParams.put("ur","https://wx.dmjjoa.com/zy/yueche.php");

        okHttpUtils.sendGet(messageUrl,null,messageParams,new Object());
        //给司机发送约车人信息
        String uid2 = SjNo;
        String tit2 = "出车提醒";
        String txt2 = "有新的出行任务：约车人为 "+yuemen+" ，预计出发时间为 "+YueStartDate+" ,目的地为 "+ArrivePlace+" ,约车人手机号为 "+YueManPhoneNo;
        String ur2 = "https://wx.dmjjoa.com/zy/chuche.php";
        sendMessage(uid2,tit2,txt2,ur2);
        return data;
    }

    /*####################################################################################*/
    /*##############################   车辆调度管理--派车    #############################*/
    /*####################################################################################*/
    /**
     * @Description 查询所有派车车辆调度信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllPaiDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllPaiDis(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllPaiDis";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 派车返回
     * @Author zhangxue
     * @Date 15:59 2018/7/30
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/SaveFanInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String SaveFanInfo(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/SaveFanInfo";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /*####################################################################################*/
    /*##########################   车辆调度管理--车辆返回    #############################*/
    /*####################################################################################*/
    /**
     * @Description 查询所有车辆返回信息
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllFanDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllFanDis(@RequestBody Map<String,Object> param, HttpSession session){
        String url = BACKURL+"/queryAllFanDis";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 查询所有约车店面
         * @Author zhangxue
         * @Date 10:39 2018/10/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllYueStore",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> queryAllYueStore(){
        String url = BACKURL+"/queryAllYueStore";
        Map<String,Object> resultMap = SessionAndGetRemote.getRemoteResult(null,url,okHttpUtils);
        return resultMap;
    }

    /**
     * @Description 车辆返回信息数据统计
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllFanData",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllFanDis(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/queryAllFanData";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 修改车辆返回信息
     * @Author zhangxue
     * @Date 15:59 2018/7/30
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/EditFan",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String EditFan(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/EditFan";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /*####################################################################################*/
    /*##########################   车辆调度管理--车辆加油管理    #########################*/
    /*####################################################################################*/
    /**
         * @Description 保存加油记录
         * @Author zhangxue
         * @Date 9:37 2018/11/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/saveRefuel",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveRefuel(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/saveRefuel";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 编辑加油记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editRefuel",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String editRefuel(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/editRefuel";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 删除加油记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delRefuel",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delRefuel(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delRefuel";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 查询所有加油记录
         * @Author zhangxue
         * @Date 10:58 2018/11/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllRefuel",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllRefuel(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/queryAllRefuel";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /*####################################################################################*/
    /*##########################   车辆调度管理--车辆违章管理    #########################*/
    /*####################################################################################*/
    /**
     * @Description 保存违章记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveBreakRule",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveBreakRule(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/saveBreakRule";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 处理违章记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editBreakRule",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String editBreakRule(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/editBreakRule";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 删除违章记录
         * @Author zhangxue
         * @Date 16:00 2018/11/22
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delBreakRule",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delBreakRule(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delBreakRule";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 查询所有违章记录
     * @Author zhangxue
     * @Date 10:58 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllBreakRule",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllBreakRule(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/queryAllBreakRule";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /*####################################################################################*/
    /*##########################   车辆调度管理--车辆维修管理    #########################*/
    /*####################################################################################*/
    /**
     * @Description 保存维修记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveService",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveService(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/saveService";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 编辑维修记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editService",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String editService(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/editService";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 删除维修记录
     * @Author zhangxue
     * @Date 9:37 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delService",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delService(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/delService";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 查询所有维修记录
     * @Author zhangxue
     * @Date 10:58 2018/11/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllService",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryAllService(@RequestBody Map<String,Object> param){
        String url = BACKURL+"/queryAllService";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
         * @Description 导出维修Excel
         * @Author zhangxue
         * @Date 9:48 2018/11/21
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/inportServiceExcel",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public void inportServiceExcel(HttpServletRequest request, HttpServletResponse response, ServletOutputStream out){
        Map<String,Object> param = new HashMap<String, Object>();
        String CarNo = request.getParameter("CarNo")!=null?request.getParameter("CarNo").toString():"";
        String ServiceStartDate = request.getParameter("ServiceStartDate")!=null?request.getParameter("ServiceStartDate").toString():"";
        String ServiceEndDate = request.getParameter("ServiceEndDate")!=null?request.getParameter("ServiceEndDate").toString():"";
        try {
            CarNo = URLDecoder.decode(CarNo, "UTF-8");
            ServiceStartDate = URLDecoder.decode(ServiceStartDate, "UTF-8");
            ServiceEndDate = URLDecoder.decode(ServiceEndDate, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        param.put("CarNo",CarNo);
        param.put("ServiceStartDate",ServiceStartDate);
        param.put("ServiceEndDate",ServiceEndDate);
        JSONObject jsonObject = JSONObject.fromObject(param);
        Map<String,String> headersParams = new HashMap<String,String>();
        headersParams.put("Content-Type","application/json;UTF-8");
        Map<String,Object> resultMap = okHttpUtils.sendPostJson(BACKURL+"/queryAllService",headersParams,jsonObject.toString(),new Object());
        String tempStr = resultMap.get("data").toString();
        JSONObject js = new JSONObject();
        js = JSONObject.fromObject(tempStr);
        JSONArray ja = JSONArray.fromObject(js.get("data"));
        List list = new ArrayList();
        for(int i=0;i<ja.size();i++){
            ServiceExcel serviceExcel = new ServiceExcel();
//            serviceExcel.setID(jxJson("ID",ja.get(i).toString()));
            serviceExcel.setCarNo(jxJson("CarNo",ja.get(i).toString()));
            serviceExcel.setServiceDate(jxJson("ServiceDate",ja.get(i).toString()));
            serviceExcel.setServiceMan(jxJson("ServiceMan",ja.get(i).toString()));
            serviceExcel.setServiceFactory(jxJson("ServiceFactory",ja.get(i).toString()));
            serviceExcel.setServiceInfo(jxJson("ServiceInfo",ja.get(i).toString()));
            serviceExcel.setMaterialMoney(jxJson("MaterialMoney",ja.get(i).toString()));
            serviceExcel.setManhourMoney(jxJson("ManhourMoney",ja.get(i).toString()));
            serviceExcel.setTotalMoney(jxJson("TotalMoney",ja.get(i).toString()));
//            serviceExcel.setCreateTime(jxJson("CreateTime",ja.get(i).toString()));
            serviceExcel.setCreateMan(jxJson("CreateMan",ja.get(i).toString()));
            serviceExcel.setRemark(jxJson("Remark",ja.get(i).toString()));
            list.add(serviceExcel);
        }
        // 第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("车辆维修记录");
        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

        HSSFCell cell = row.createCell((short) 0);
        cell.setCellValue("车牌号");
        cell.setCellStyle(style);
        cell = row.createCell((short) 1);
        cell.setCellValue("维修时间");
        cell.setCellStyle(style);
        cell = row.createCell((short) 2);
        cell.setCellValue("维修人");
        cell.setCellStyle(style);
        cell = row.createCell((short) 3);
        cell.setCellValue("修理厂");
        cell.setCellStyle(style);
        cell = row.createCell((short) 4);
        cell.setCellValue("材料费明细");
        cell.setCellStyle(style);
        cell = row.createCell((short) 5);
        cell.setCellValue("材料费合计");
        cell.setCellStyle(style);
        cell = row.createCell((short) 6);
        cell.setCellValue("工时费合计");
        cell.setCellStyle(style);
        cell = row.createCell((short) 7);
        cell.setCellValue("总金额");
        cell.setCellStyle(style);
//        cell = row.createCell((short) 8);
//        cell.setCellValue("创建时间");
//        cell.setCellStyle(style);
        cell = row.createCell((short) 8);
        cell.setCellValue("创建人");
        cell.setCellStyle(style);
        cell = row.createCell((short) 9);
        cell.setCellValue("备注");
        cell.setCellStyle(style);


        // 第五步，写入实体数据 实际应用中这些数据从数据库得到，

        for (int i = 0; i < list.size(); i++)
        {
            row = sheet.createRow((int) i + 1);
            ServiceExcel serviceExcel = (ServiceExcel) list.get(i);
            // 第四步，创建单元格，并设置值
            row.createCell((short) 0).setCellValue(serviceExcel.getCarNo());

            row.createCell((short) 1).setCellValue(serviceExcel.getServiceDate());
//            cell = row.createCell((short) 1);
//            String serviceDateStr = formatData("yyyy-MM-dd",Long.valueOf(serviceExcel.getServiceDate()));
//            cell.setCellValue(serviceDateStr);

            row.createCell((short) 2).setCellValue(serviceExcel.getServiceMan());
            row.createCell((short) 3).setCellValue(serviceExcel.getServiceFactory());
            row.createCell((short) 4).setCellValue(serviceExcel.getServiceInfo());
            row.createCell((short) 5).setCellValue(serviceExcel.getMaterialMoney());
            row.createCell((short) 6).setCellValue(serviceExcel.getManhourMoney());
            row.createCell((short) 7).setCellValue(serviceExcel.getTotalMoney());
//            row.createCell((short) 8).setCellValue(serviceExcel.getCreateTime());
//            cell = row.createCell((short) 8);
//            String createTimeStr = formatData("yyyy-MM-dd hh:mm:ss",Long.valueOf(serviceExcel.getCreateTime()));
//            cell.setCellValue(createTimeStr);

            row.createCell((short) 8).setCellValue(serviceExcel.getCreateMan());
            row.createCell((short) 9).setCellValue(serviceExcel.getRemark());

        }
        // 第六步，将文件存到指定位置
        try
        {
//            response.setHeader(
//                    "Content-disposition",
//                    "attachment; filename="
//                            + new String(
//                            ("D:/AssessExcel/AssessExcel.xls").getBytes("GB2312"),
//                            "ISO8859-1"));
            // 设定输出文件头
            response.setContentType("application/vnd.ms-excel");
            wb.write(out);
            out.flush();
            out.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }


    /*####################################################################################*/
    /*##########################   车辆调度管理--手机端接口    #############################*/
    /*####################################################################################*/
    /**
         * @Description 查询司机任务以及历史记录(手机端接口)
         * @Author zhangxue
         * @Date 14:24 2018/8/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/querySjTaskBySjNo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String querySjTaskBySjNo(HttpServletRequest request){
        Map<String,Object> paramMap = new HashMap<String, Object>();
        String SjNo = request.getParameter("SjNo");
        String Status = request.getParameter("Status");
        if(Status==null||"".equals(Status)||SjNo==null||"".equals(SjNo)){
            return null;
        }
        paramMap.put("SjNo",SjNo);
        paramMap.put("Status",Status);
        String url = BACKURL+"/querySjTaskBySjNo";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(paramMap,url,okHttpUtils);
        String dataStr = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return dataStr;
    }

    /**
         * @Description 约车接口
         * @Author zhangxue
         * @Date 15:03 2018/8/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/yueche",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String yueche(HttpServletRequest request){
        Map<String,Object> paramMap = new HashMap<String, Object>();
        long DocNo = System.currentTimeMillis();
        String YueStore = request.getParameter("YueStore");
        if(YueStore==null||"".equals(YueStore)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车人中心店面");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        String YueBm = request.getParameter("YueBm");
        if(YueBm==null||"".equals(YueBm)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车人部门");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        String YueManNo = request.getParameter("YueManNo");
        if(YueManNo==null||"".equals(YueManNo)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车人员工编号");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        String YueMan = request.getParameter("YueMan");
        if(YueMan==null||"".equals(YueMan)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车人姓名");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //目的地
        String ArrivePlace = request.getParameter("ArrivePlace");
        if(ArrivePlace==null||"".equals(ArrivePlace)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车目的地");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //约车开始时间 YueStartDate
        String YueStartDate = request.getParameter("YueStartDate");
        if(YueStartDate==null||"".equals(YueStartDate)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入预计出发时间");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //预计到达时间
        String YueEndDate = request.getParameter("YueEndDate");
        if(YueEndDate==null||"".equals(YueEndDate)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入预计到达时间");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //约车事由
        String YueReason = request.getParameter("YueReason");
        if(YueReason==null||"".equals(YueReason)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入约车事由");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //同行人数
        String YueManNumber = request.getParameter("YueManNumber");
        if(YueManNumber==null||"".equals(YueManNumber)){
            Map<String,Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Info","请传入同行人数");
            JSONObject js = JSONObject.fromObject(resultMap);
            return js.toString();
        }
        //随车物品描述
        String YueGoods = request.getParameter("YueGoods");
        //约车特殊情况
        String YueSpecialExplain = request.getParameter("YueSpecialExplain");
        paramMap.put("DocNo",DocNo);
        paramMap.put("YueStore",YueStore);
        paramMap.put("YueBm",YueBm);
        paramMap.put("YueManNo",YueManNo);
        paramMap.put("YueMan",YueMan);
        paramMap.put("ArrivePlace",ArrivePlace);
        paramMap.put("YueStartDate",YueStartDate);
        paramMap.put("YueEndDate",YueEndDate);
        paramMap.put("YueReason",YueReason);
        paramMap.put("YueManNumber",YueManNumber);
        paramMap.put("YueGoods",YueGoods);
        paramMap.put("YueSpecialExplain",YueSpecialExplain);
        String url = BACKURL+"/yueche";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(paramMap,url,okHttpUtils);
        String dataStr = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        JSONObject jb = JSONObject.fromObject(dataStr);
        Map<String, Object> data = (Map<String, Object>)jb;
        String statusstr = data.get("Status")!=null?data.get("Status").toString():"0";

        //发送约车信息给派车人
        String paiListStr = data.get("paiList")!=null?data.get("paiList").toString():null;
        JSONArray paiArr = JSONArray.fromObject(paiListStr);
        String uid = "";
        for(int i=0;i<paiArr.size();i++){
            String usernoMapStr = paiArr.get(i)!=null?paiArr.get(i).toString():null;
            Map<String,Object> userNoMap = JSONObject.fromObject(usernoMapStr);
            String userno = userNoMap.get("UserNo")!=null?userNoMap.get("UserNo").toString():null;
            if(userno!=null){
                uid += "|"+userno;
            }
        }
        uid = uid.substring(1);
        //给派车人发送约车信息

        if(uid==null||"".equals(uid)){
            Map<String,Object> tempMap = new HashMap<String, Object>();
            tempMap.put("info","员工编号未传入");
        }
        String txt = YueStore+" "+YueBm+" "+YueMan+"已约车，预计出发时间为： "+YueStartDate+",预计返程时间为: "+YueEndDate+"，目的地为 "+ArrivePlace;
        sendMessage(uid,"约车提醒",txt,null);

        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("Status",statusstr);
        JSONObject js = JSONObject.fromObject(resultMap);
        return js.toString();
    }

    /**
     * @Description 查询所有车辆调度信息(手机端接口)
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllDocPhone")
    @ResponseBody
    public String queryAllDocPhone(HttpServletRequest request, HttpSession session){
        Map<String,Object> param = new HashMap<String, Object>();
        String YueManNo = request.getParameter("YueManNo")!=null?request.getParameter("YueManNo").toString():null;
        if(YueManNo==null||"".equals(YueManNo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入员工编号");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        /*String Status = request.getParameter("Status")!=null?request.getParameter("Status").toString():null;
        if(Status==null||"".equals(Status)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入单据状态");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }*/
        String Month = request.getParameter("Month")!=null?request.getParameter("Month").toString():null;
        param.put("YueManNo",YueManNo);
//        param.put("Status",Status);
        Integer year = null;
        Integer month = null;
        if(Month!=null&&!"".equals(Month)){
            String[] ym = Month.split("-");
            year = Integer.valueOf(ym[0]);
            month = Integer.valueOf(ym[1]);
        }
        param.put("month",month);
        param.put("year",year);
        String url = BACKURL+"/queryAllDoc";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }

    /**
     * @Description 派车返回(手机端接口)
     * @Author zhangxue
     * @Date 15:59 2018/7/30
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/SaveFanInfoPhone",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String SaveFanInfoPhone(HttpServletRequest request){
        String DocNo = request.getParameter("DocNo");
        if(DocNo==null||"".equals(DocNo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入单据编号");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String SjNo = request.getParameter("SjNo");
        if(SjNo==null||"".equals(SjNo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入司机员工编号");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String PaiCarNo = request.getParameter("PaiCarNo");
        if(PaiCarNo==null||"".equals(PaiCarNo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入所派车辆车牌号");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String FanPlace = request.getParameter("FanPlace");
        if(FanPlace==null||"".equals(FanPlace)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入车辆停放位置");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String FanKilometers = request.getParameter("FanKilometers");
        if(FanKilometers==null||"".equals(FanKilometers)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入车辆公里数");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String GaosuCost = request.getParameter("GaosuCost");
        if(GaosuCost==null||"".equals(GaosuCost)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入高速费");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String StandCost = request.getParameter("StandCost");
        if(StandCost==null||"".equals(StandCost)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入停车费");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String OtherCost = request.getParameter("OtherCost");
        if(OtherCost==null||"".equals(OtherCost)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入其他费用");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String FanCost = request.getParameter("FanCost");
        if(FanCost==null||"".equals(FanCost)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入总费用");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        String FanRemark = request.getParameter("FanRemark");
        Map<String,Object> param = new HashMap<String, Object>();
        param.put("FanPlace",FanPlace);
        param.put("FanKilometers",FanKilometers);
        param.put("GaosuCost",GaosuCost);
        param.put("StandCost",StandCost);
        param.put("OtherCost",OtherCost);
        param.put("FanCost",FanCost);
        param.put("FanRemark",FanRemark);
        param.put("PaiCarNo",PaiCarNo);
        param.put("SjNo",SjNo);
        String url = BACKURL+"/SaveFanInfoPhone";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        Map<String,Object> PaiManMap = JSONObject.fromObject(data);
        String status = PaiManMap.get("Status")!=null?PaiManMap.get("Status").toString():null;
        if("-2".equals(status)){
            Map<String,Object> tempMap = new HashMap<String, Object>();
            tempMap.put("info","您输入的公里数有错误");
            JSONObject js = JSONObject.fromObject(tempMap);
            return js.toString();
        }

        //发送车辆返回信息给派车人
        String paiListStr = PaiManMap.get("paiList")!=null?PaiManMap.get("paiList").toString():null;
        JSONArray paiArr = JSONArray.fromObject(paiListStr);
        String uid = "";
        for(int i=0;i<paiArr.size();i++){
            String usernoMapStr = paiArr.get(i)!=null?paiArr.get(i).toString():null;
            Map<String,Object> userNoMap = JSONObject.fromObject(usernoMapStr);
            String userno = userNoMap.get("UserNo")!=null?userNoMap.get("UserNo").toString():null;
            if(userno!=null){
                uid += "|"+userno;
            }
        }
        uid = uid.substring(1);
        if(uid==null||"".equals(uid)){
            Map<String,Object> tempMap = new HashMap<String, Object>();
            tempMap.put("info","信息发送失败");
            return tempMap.toString();
        }
        String txt = PaiCarNo+" 已返回，车辆停放位置为 "+FanPlace+" ,总花费为: "+FanCost+" 元。";
        sendMessage(uid,"车辆返回提醒",txt,null);

        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("status",status);
        JSONObject js = JSONObject.fromObject(resultMap);
        return js.toString();
    }

    /**
     * @Description 查询当前行驶公里数(手机端接口)
     * @Author zhangxue
     * @Date 12:45 2018/5/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryNowFankilo")
    @ResponseBody
    public String queryNowFankilo(HttpServletRequest request, HttpSession session){
        Map<String,Object> param = new HashMap<String, Object>();
        String CardNo = request.getParameter("CardNo")!=null?request.getParameter("CardNo").toString():null;
        String FanEndKilo = request.getParameter("FanEndKilo")!=null?request.getParameter("FanEndKilo").toString():null;
        if(CardNo==null||"".equals(CardNo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入车牌号");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        if(FanEndKilo==null||"".equals(FanEndKilo)){
            Map<String,Object> statusMap = new HashMap<String, Object>();
            statusMap.put("info","未传入车辆当前公里数");
            JSONObject js = JSONObject.fromObject(statusMap);
            return js.toString();
        }
        param.put("CardNo",CardNo);
        param.put("FanEndKilo",FanEndKilo);
        String url = BACKURL+"/queryNowFankilo";
        Map<String,Object> statusMap = SessionAndGetRemote.getRemoteResult(param,url,okHttpUtils);
        String data = statusMap.get("data")!=null?statusMap.get("data").toString():null;
        return data;
    }





    public void sendMessage(String uid,String tit,String txt,String ur){
        Md5Util md5Util = new Md5Util();
        String mak = "";
        try {
            mak = md5Util.get32Md5Up(uid);
        }catch (Exception e){
            e.printStackTrace();
        }
        String messageUrl = "https://wx.dmjjoa.com/hui.php";
        Map<String,String> messageParams = new HashMap<String, String>();
        messageParams.put("uid",uid);
        messageParams.put("mak",mak);
        messageParams.put("lei","bh");
        messageParams.put("tit",tit);

        messageParams.put("txt",txt);
        messageParams.put("ur",ur);

        okHttpUtils.sendGet(messageUrl,null,messageParams,new Object());
    }

    public String jxJson(String mkey, String strJson) {
        String value = "";
        try {
            JSONObject json = JSONObject.fromObject(strJson);
            Iterator iterator = json.keys();
            while (iterator.hasNext()) {
                String key = iterator.next() + "";

                if (json.getString(key).startsWith("{")) {
                    value = jxJson(mkey, json.getString(key));
                    break;
                } else {
                    if (key.equals(mkey)) {
                        value = json.getString(key);
                        break;
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (value.equals("null")) {
            value = "";
        }
        return value;
    }

    /**
     * 时间戳转换成日期格式字符串
     * @param
     * @param
     * @return
     */
    public static String formatData(String dataFormat, long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        SimpleDateFormat format = new SimpleDateFormat(dataFormat);
        return format.format(new Date(timeStamp));
    }
}
